﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestVisioCanvas.Helpers
{
	/// <summary>
	/// Contains a page setup complete of height and width of the paper,
	/// and the scale of both page and drawing.
	/// </summary>
	public struct PageSetup
	{
		#region Properties Definition
		
		private double _PageScale_field;
		private double _DrawingScale_field;
		private double _paperWidth_field;
		private double _paperHeight_field;
		private double _preferredZoom;
			  
		/// <summary>
		/// Returns the scaling factor of the page
		/// </summary>
		public double PageScale 
		{ 
			get {return _PageScale_field;}
		}
		/// <summary>
		/// Returns the scaling factor of the drawing
		/// </summary>
		public double DrawingScale 
		{ 
			get {return _DrawingScale_field;}
		}
		/// <summary>
		/// Returns the width of the page intended as paper width * drawing scale
		/// </summary>
		public double PageWidth
		{ 
			get {return _paperWidth_field*DrawingScale;}
		}
		/// <summary>
		/// Returns the height of the page intended as paper height * drawing scale
		/// </summary>
		public double PageHeight
		{ 
			get {return _paperHeight_field*DrawingScale;}			
		}

		/// <summary>
		/// Returns the preferred zoom of the Drawing for the specified paper format and scale
		/// </summary>
		public double PreferredZoom
		{
			get { return _preferredZoom; }			
		}

		/// <summary>
		/// Returns a Point that represents the center of the page expressed in the
		/// used unit of measure (CM)
		/// </summary>
		public System.Windows.Point PageCenter
		{
			get
			{
				return new System.Windows.Point()
				  {
					  X = PageWidth / 2,
					  Y = PageHeight / 2
				  };
			}
		}

		public double ScalingFactor
		{
			get
			{
				return _PageScale_field / _DrawingScale_field;
			}
		}

		#endregion
		
		/// <summary>
		/// Unique constructor of the class
		/// </summary>
		/// <remarks>Paper Height and Width represent the phisical dimensions of
		/// the drawing paper. Page and drawing scale are used in order to
		/// create a correct scaled drawing paper.
		/// e.g. Page Scale = 1 and Drawing Scale = 100 means that 
		/// 1cm on the drawing paper represents 100cm on the "real" world </remarks>
		/// <param name="PaperWidth">Phisical width of the paper</param>
		/// <param name="PaperHeight">Phisical height of the paper</param>
		/// <param name="PageScale">Scaling factor of the page</param>
		/// <param name="DrawingScale">Scaling factor of the drawing</param>
        /// <param name="PreferredZoom">Preferred zoom of the drawing</param>
		public PageSetup(double PaperWidth, double PaperHeight, double PageScale, double DrawingScale, double PreferredZoom)
		{
			this._DrawingScale_field = DrawingScale;
			this._PageScale_field = PageScale;
			this._paperHeight_field = PaperHeight;
			this._paperWidth_field = PaperWidth;
			this._preferredZoom = PreferredZoom;
		}
	}

	/// <summary>
	/// Provides the most common page setups.
	/// </summary>
	public sealed class PageStandards
	{
		public static readonly PageSetup A4OnetoFiftyHorizontalPage = 
			new PageSetup(297.0, 210.0, 1.0, 50.0, 0.7);

		public static readonly PageSetup A4OnetoHundredHorizontalPage =
            new PageSetup(297.0, 210.0, 1.0, 100.0, 0.6);

		public static readonly PageSetup A3OnetoFiftyHorizontalPage =
            new PageSetup(420.0, 297.0, 1.0, 50.0, 0.3);

		public static readonly PageSetup A3OnetoHundredHorizontalPage =
            new PageSetup(420.0, 297.0, 1.0, 100.0, 0.3);
		
		public static PageSetup GetPageSetup(PaperFormat format, Scale scale)
		{
			return
				format == PaperFormat.A3 ?
				(scale == Scale.OneToFifty ? A3OnetoFiftyHorizontalPage : A3OnetoHundredHorizontalPage) :
				(scale == Scale.OneToFifty ? A4OnetoFiftyHorizontalPage : A4OnetoHundredHorizontalPage);
		}

		// Prevents class instancing
		private PageStandards() { }			
	}
	

	public enum RoomType
	{
		Room,
		TRoom,
		LRoom  
	}
	public enum PaperFormat
	{
		A4,A3        
	}
	public enum Scale
	{
		OneToFifty,
		OneToHundred
	}
}
